package com.clickpaas.workinghours.service.Impl;

import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.  d20210220155135.model.TimeCardDateDTO;
import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.  d20210220155135.model.TimeCardDateDTOResponse;
import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.  d20210220155135.model.TimeCardDateSaveOrUpdateDataResponseObject;
import com.clickpaas.workinghours.dao.TimeCardDateDao;
import com.clickpaas.workinghours.entity.TimeCardDateEntity;
import com.clickpaas.workinghours.service.TimeCardDateService;
import com.clickpaas.workinghours.utils.DataInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class TimeCardDateServiceImpl implements TimeCardDateService {
    @Resource
    private TimeCardDateDao timeCardDateDao;
    /**
     * 获取数据
     *
     * @param entity
     * @return
     */
    @Override
    public List<TimeCardDateDTO> getDataInfo(TimeCardDateEntity entity) {
        List<TimeCardDateDTO> reList;
        try {
            reList = DataInfoUtil.castListCopy(timeCardDateDao.queryDataInfo(entity), TimeCardDateDTOResponse.class, TimeCardDateDTO.class);
        } catch (Exception e) {
            log.info("入参对象异常,请检查：【{}】,报错信息：【{}】",entity,e);
            return null;
        }
        if (null != reList && reList.size()>0){
            return reList;
        }
        return null;
    }

    /**
     * 数据转换为bean
     *
     * @param list
     * @return
     */
    @Override
    public List<TimeCardDateEntity> DataConver(List<TimeCardDateDTO> list) {
        return DataInfoUtil.castListCopy(list,TimeCardDateDTO.class,TimeCardDateEntity.class);
    }

    /**
     * 工时日期数据入库
     *
     * @param entity
     * @return
     */
    @Override
    public TimeCardDateSaveOrUpdateDataResponseObject insertDataInfo(TimeCardDateEntity entity) {
        return timeCardDateDao.insertDataInfo(entity);
    }

    /**
     * 工时日期数据更新
     *
     * @param query
     * @param update
     * @return
     */
    @Override
    public TimeCardDateSaveOrUpdateDataResponseObject updateDataInfo(TimeCardDateEntity query, TimeCardDateEntity update) {
        return timeCardDateDao.updateDataInfo(query,update);
    }
}
